package com.github.ylt.protocol.parser;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.util.HashMap;
import java.util.List;

public class SoapParser {

    private SoapParser() {}

    // 解析SOAP消息的方法
    public static HashMap<String,String> parseSoapMessage(String soapMessage) throws DocumentException {
        HashMap<String,String> map = new HashMap<>();
        Document doc = DocumentHelper.parseText(soapMessage);
        if(doc.getRootElement().element("Body") != null) {
            List<Element> elements = doc.getRootElement().element("Body").elements().get(0).elements();
            for (Element element : elements) {
                map.put(element.getName(), element.getText());
            }
        }
        return map;
    }
}